package com.uyayo.portal.biz;

import com.uyayo.framework.message.model.Result;
import com.uyayo.framework.common.util.HttpClientUtil;
import com.uyayo.system.authority.entity.SysUser;
import com.uyayo.system.config.service.SysParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 用户管理Service
 * <p>Title: UserServiceImpl</p>
 * <p>Description: </p>
 * <p>Company: www.itcast.com</p> 
 * @author	入云龙
 * @date	2015年9月15日上午10:54:10
 * @version 1.0
 */
@Component
public class HomeBiz {
	
	@Autowired
	private SysParamService paramsService;
	
	public SysUser getUserByToken(String token) {
		String SSO_DOMAIN_BASE_USRL = paramsService.getSysParamValueByCode("SSO_BASE_URL");  //单点登录域名基本路径
		String SSO_USER_TOKEN = paramsService.getSysParamValueByCode("SSO_USER_TOKEN");  //单点登录登录路径
		
		try {
			//调用sso系统的服务，根据token取用户信息
			String json = HttpClientUtil.doGet(SSO_DOMAIN_BASE_USRL + SSO_USER_TOKEN + token);
			//把json转换成TaotaoREsult
			Result result = Result.formatToPojo(json, SysUser.class);
			if (result.getStatus() == 200) {
				SysUser user = (SysUser) result.getData();
				return user;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	public Result logoutUserByToken(String token) {
		String SSO_DOMAIN_BASE_USRL = paramsService.getSysParamValueByCode("SSO_BASE_URL");  //单点登录域名基本路径
		String SSO_USER_LOGOUT = paramsService.getSysParamValueByCode("SSO_USER_LOGOUT");  //单点登录用户注销路径
		
		try {
			//调用sso系统的服务，根据token取用户信息
			String json = HttpClientUtil.doGet(SSO_DOMAIN_BASE_USRL + SSO_USER_LOGOUT + token);
			
			//把json转换成TaotaoREsult
			Result result = Result.format(json);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Result.build(500, "注销失败！");
	}

}
